package com.gxa.j259.springcloud.f.client.controller;

import com.netflix.ribbon.proxy.annotation.Http;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;

/**
 * @author thinknovo
 * @version 1.0
 */
@RestController
public class TestController {
    @GetMapping("/get")
    public String get() {
        return "hello springcloud 8861";
    }

    @Value("${server.port}")
    private int port;

    // 注入远程仓库中的配置属性对应的值
    @Value("${username}")
    private String usernameBus;

    @GetMapping("/check")
    public Map check(String username, @RequestHeader String token, HttpServletRequest request) {
        Map objectObjectHashMap = new HashMap();
        System.out.println("来自请求服务 端口：" + request.getLocalPort());
        System.out.println("来自请求服务 token：" + token);
        objectObjectHashMap.put("code", 200);
        objectObjectHashMap.put("port", port);
        objectObjectHashMap.put("token", token);
        objectObjectHashMap.put("str", username);
        objectObjectHashMap.put("msg", "请求服务提供者成功");
        return objectObjectHashMap;
    }

    @GetMapping("/check2")
    public Map check2(HttpServletRequest request) {
        Map objectObjectHashMap = new HashMap();
        System.out.println("来自请求服务 端口：" + request.getLocalPort());
        objectObjectHashMap.put("code", 200);
        objectObjectHashMap.put("method", "check2");
        objectObjectHashMap.put("port", port);
        objectObjectHashMap.put("usernameBus", usernameBus);
        objectObjectHashMap.put("msg", "请求服务提供者成功");
        return objectObjectHashMap;
    }
}

